#ifndef __CENGINE_H__
#define __CENGINE_H__

#include <WinSock2.h>
#include <Windows.h>
#include <vector>
#include "CPacket.h"

enum CEngineConnectionState {
	IDCS_DISCONNECTED = 1,
	IDCS_CONNECTING,
	IDCS_CONNECTED
} ;

class CEngine {
public:
	CEngine()													;

	static BOOL			Initialize(void)						;
	
	static void			Uninitialize(void)						;

	SOCKET				GetClientSocket(void)					;

	CPacket*			GetNextPacket(void)						;

	void				Send(CPacket* pPkt)						;

	static DWORD WINAPI IncomingPacketThread(LPVOID lpParam)	;

	static DWORD WINAPI OutgoingPacketThread(LPVOID lpParam)	;

	void				Connect(const char* lpszHostname)		;

	enum CEngineConnectionState	GetConnectionState(void)		;

	void				Disconnect(void)						;

	~CEngine()													;
private:
	void			_RecvProc(void)								;

	void			_SendProc(void)								;

	CPacket*		_GetNextSendPacket(void)					;
protected:
	SOCKET					m_ClientSocket						;
	BOOL					m_bConnected						;
	CPacket*				m_pCurrentRecv						;
	CPacket*				m_pCurrentSend						;
	std::vector<CPacket*>	m_RecvQueue							;
	std::vector<CPacket*>	m_SendQueue							;
} ;

#endif
